package cn.yll.web.controller;

import cn.yll.api.order.response.GoodResponse;
import cn.yll.api.order.service.RemoteGoodFeinService;
import cn.yll.common.exception.BsErrEnum;
import cn.yll.common.module.PageModel;
import cn.yll.common.module.PageRequest;
import cn.yll.common.module.RestModel;
import cn.yll.api.util.RestUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * @author yangll
 */
@Slf4j
@Api(tags = "商品接口服务")
@RestController
@RequestMapping("goods")
public class GoodsController extends BaseController {

    @Autowired
    private RemoteGoodFeinService remoteGoodFeinService;

    @PostMapping("/findGoodsByPage")
    @ApiOperation(value = "分页查询商品列表")
    public RestModel<PageModel<GoodResponse>> findGoodsByPage(@RequestBody PageRequest request) {
        if (Objects.isNull(request) || Objects.isNull(request.getPageNum()) || Objects.isNull(request.getPageSize())) {
            return RestUtil.error(BsErrEnum.PARAM_EMPTY);
        }
        return remoteGoodFeinService.findGoodsByPage(request);
    }
}
